﻿using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Resources;

namespace ShaoLuWinFormsApp
{
    public class LanguageHelper
    {

        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 设定语言环境
        /// </summary>
        /// <param name="strClutrue"></param>
        public static void SetLocalClutrue(string strClutrue)
        {
            if (string.IsNullOrEmpty(strClutrue))
            {
                strClutrue = "zh-CN";
            }
            CultureInfo currentClutrue = new CultureInfo(strClutrue);
            Thread.CurrentThread.CurrentCulture = currentClutrue;
            Logger.Info(" The Language is : " + strClutrue);
        }

        /// <summary>
        /// 获取指定 Name 的值
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetString(string name)
        {
            string strValue = string.Empty;
            try
            {

                //ShaoLuWinFormsApp,为应用程序集名称，在项目 - 属性里查看
                ResourceManager resManager = new ResourceManager("ShaoLuWinFormsApp.Resource", Assembly.GetExecutingAssembly());
                strValue = resManager.GetString(name, Thread.CurrentThread.CurrentCulture);
            }
            catch
            {
                strValue = "NullText";
            }
            return strValue;
        }
    }

}
